sp_msforeachdb 'use ? if exists (select ''?'' + ''..'' + object_name(id) from syscomments where text like ''% cursor%'' and object_name(id) not like ''dt_%'' and object_name(id) not in (''update_all_stats'',''size_all_tables'') and db_name() not in (''master'',''msdb'',''model'',''tempdb'')) select distinct ''?.'' + user_name(objectproperty(id, ''ownerid'')) + + ''.'' + object_name(id) from syscomments where text like ''%cursor%'' and object_name(id) not like ''dt_%'' and object_name(id) not in (''update_all_stats'',''size_all_tables'') and db_name() not in (''master'',''msdb'',''model'',''tempdb'')'